<%--
  Created by IntelliJ IDEA.
  User: wwh
  Date: 2017/8/4
  Time: 13:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>实习变更申请</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="../../static/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/global.css">
</head>
<body>
<div style="width: 50%;height: 100%;overflow:scroll;float: left">
    <fieldset class="layui-elem-field">
        <legend>目前实习信息</legend>
        <form id="contentNow" class="layui-form" action="" method="">
            <div class="layui-form-item">
                <label class="layui-form-label">用人单位</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="org" v-model="orgInfo.fullname" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习岗位</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="position" v-model="internInfo.position" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">岗位介绍</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" name="jobintro" disabled>{{ internInfo.jobintro }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习内容</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" disabled>{{ internInfo.jobcontent }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习成果</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" value="" disabled>{{ internInfo.outcome }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">办公环境</label>
                <img id="nowWorkPic" style="height: 100px;width: 100px" disabled>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习单位指导老师</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="instructor" v-model="internInfo.instructor" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">单位老师联系电话</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="instructorphone" v-model="internInfo.instructorphone" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">审核意见</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" name="auditsug" disabled>{{ internInfo.auditsug }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="startTime" v-model="getYearMonthDate(internInfo.start)" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="endTime" v-model="getYearMonthDate(internInfo.end)" disabled>
                </div>
            </div>
        </form>
    </fieldset>
</div>
<div style="width: 50%;height: 100%;overflow:scroll;float: right">
    <fieldset class="layui-elem-field">
        <legend>新申请实习信息</legend>
        <form id="contentWant" class="layui-form" action="" method="">
            <div class="layui-form-item">
                <label class="layui-form-label">用人单位</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="org" v-model="orgInfo.fullname" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习岗位</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="position" v-model="internInfo.position" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">岗位介绍</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" name="jobintro" disabled>{{ internInfo.jobintro }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习内容</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" disabled>{{ internInfo.jobcontent }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习成果</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" value="" disabled>{{ internInfo.outcome }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">办公环境</label>
                <img id="futureWorkPic" style="height: 100px;width: 100px" disabled>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习单位指导老师</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="instructor" v-model="internInfo.instructor" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">单位老师联系电话</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="instructorphone" v-model="internInfo.instructorphone" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">审核意见</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" name="auditsug" disabled>{{ internInfo.auditsug }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="startTime" v-model="getYearMonthDate(internInfo.start)" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="endTime" v-model="getYearMonthDate(internInfo.end)" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="button" class="layui-btn" lay-filter="pass" value="审核通过" lay-submit style="display: none">
                    <input type="button" class="layui-btn" lay-filter="reject" value="审核不通过" lay-submit style="display: none">
                    <input type="button" class="layui-btn layui-btn-primary" @click="reload" value="返回">
                </div>
            </div>
        </form>
    </fieldset>
</div>
<script type="text/javascript" src="../../static/common/layui/layui.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=8K08Q6AWX7LcrskmDiE6BFSG5LqUfGGE"></script>
<script src="../../static/common/vue.min.js"></script>
<script src="../../static/common/axios.min.js"></script>
<script>
    var studentInfoId = <%=request.getParameter("studentInfoId")%>;
    var studentUserId = <%=request.getParameter("studentUserId")%>;
    var studentInfo = {};
//    console.log(studentInfoId);
    /**
     * 时间格式取年月日
     * @param time
     * @returns {*}
     */
    function getYearMonthDate(time) {
//        console.log(time);
        if(time!=null) {
            var YMD = time.split(" ")[0];  // 年月日
            var HMS = time.split(" ")[1];  // 时分秒
            return YMD;
        }
        return null;
    }
layui.use(['form','jquery','layer'],function () {
    var form = layui.form(),
        $ = layui.jquery,
        layer = layui.layer,
        image = {};
    var vmNow = new Vue({
        el:'#contentNow',
        data:{
            internInfo:{
                sno:studentInfoId
            },
            orgInfo:{},
            imag:{}
        },
        methods:{
            /**
             * 得到目前实习信息
             */
            getInfo:function () {
                axios.post('/internInfo/findByCondition',{sno:studentInfoId,orgattr:2})
                    .then(function (response) {
                        console.log(response.data);
                        $('#nowWorkPic').attr('src','');
                        vmNow.internInfo = response.data.data[0].internInfo;
                        vmNow.orgInfo = response.data.data[0].orgInfo;
                        if(response.data.data[0].image!=null) {
                            vmNow.img = response.data.data[0].image;
                            $('#nowWorkPic').attr('src',vmNow.img.path);
                        }
//                        console.log(vmNow.internInfo);
//                        console.log(vmNow.orgInfo);
                    })
                    .catch(function (msg) {
                        console.log(msg);
                    })
            }
        }
    });
    vmNow.getInfo();

    var vmWant = new Vue({
        el:'#contentWant',
        data:{
            internInfo:{
                sno:studentInfoId
            },
            orgInfo:{},
            imag:{}
        },
        methods:{
            /**
             * 得到新申请的实习信息
             */
            getInfo:function () {
                axios.post('/internInfo/findByCondition',{sno:studentInfoId,orgattr:3})
                    .then(function (response) {
                        console.log(response.data);
                        vmWant.internInfo = response.data.data[0].internInfo;
                        vmWant.orgInfo = response.data.data[0].orgInfo;
                        $('#futureWorkPic').attr('src','');
                        if(response.data.data[0].image!=null) {
                            vmWant.img = response.data.data[0].image;
                            $('#futureWorkPic').attr('src',vmWant.img.path);
                        }
                        if(vmWant.internInfo.state == 2){
                            $('form input[value="审核通过"]').show();
                            $('form input[value="审核不通过"]').show();
                        }
//                        console.log(vmWant.internInfo);
//                        console.log(vmWant.orgInfo);
                    })
                    .catch(function (msg) {
                        console.log(msg);
                    })
            },
            /**
             * 返回按钮
             */
            reload:function () {
                console.log("返回");
                location.href="/teacher/internLists";
            }
        }
    });
    vmWant.getInfo();

    axios.get('/student/findDetail/'+studentUserId)
        .then(function (response) {
            console.log(response.data);
            studentInfo = response.data.data.studentInfo;
            console.log(studentInfo);
        })
        .catch(function (msg) {
            console.log(msg);
        });

    /**
     * 监听审核通过
     */
    form.on('submit(pass)',function (data) {
        console.log(123);
        layer.confirm("确认通过吗？",function (index) {
            vmWant.internInfo.state = 3; // 教师审核通过

            // 更新一条实习信息
            axios.post('/internInfo/modify',vmWant.internInfo)
                .then(function (response) {
                    if(response.data.success) {
                        layer.msg("操作成功", {icon: 1, time: 1500});
                        location.href='/teacher/internLists';
//                    history.go(-1);
                    }
                    console.log("修改实习记录成功");
                })
                .catch(function (msg) {
                    console.log(msg)
                });
        });

    });
    /**
     * 监听审核不通过
     */
    form.on('submit(reject)',function (data) {
        console.log(456);
        layer.prompt({
            formType:2,
            title:"意见",
            value:"",
            area:['300px', '150px']
        },function (value,index,elem) {
            studentInfo.state = 3;      // 实习中
            vmWant.internInfo.state = 4;    // 教师审核不通过
            axios.all([axios.post('/internInfo/modify',vmWant.internInfo),axios.post('/student/modifyOneById',studentInfo)])
                .then(function (res) {
                    if(res[0].data.success&&res[1].data.success){
                        top.layer.msg('审核不通过操作成功',{icon: 1, time: 1500});
                        layer.close(index);
                        location.href='/teacher/internLists';
                    }
                })
                .catch(function (msg) {
                    console.log(msg);
                    console.log("操作失败");
                });
        })

    });
})
</script>
</body>
</html>
